#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#define MAXN 100005
#define INF 100
using namespace std;

bool A[9][9];
int memo[9][9][1<<9][1<<3][2];

int solve(int r, int c, int mc, int mb, bool p){
    if (r == 9){
        return mc ? INF : 0;
    }
    if (c == 9){
        if (p) return INF;
        if (r%3==2 && mb) return INF;
        return solve(r+1, 0, mc, mb, 0);
    }
    int &ref = memo[r][c][mc][mb][p];
    if (ref != -1) return ref;

    ref = !A[r][c] + solve(r, c+1, mc^1 << c, mb ^ 1 << c / 3, !p);
    ref = min(ref, A[r][c] + solve(r, c+1, mc, mb,p));
    return ref;
}

int main()
{
    freopen("bsudoku.txt","r", stdin);
    for (int i=0;i<9;i++){
        string S;
        cin >> S;
        for (int j=0;j<9;j++) A[i][j] = S[j] == '1';
    }
    memset(memo, -1, sizeof(memo));
    cout << solve(0, 0, 0, 0, 0) << endl;
    return 0;
}
